import { memo, useState } from 'react'
import { useNewPage } from '@hs-admin/utils'
import { HsAdminTablePage } from '@hs-admin/base-components'
import { postCompanyInfoDetailQueryShareholderInformation } from '@/api/companyDetail/BasicInfor'

const ShareholderInformation = (props: any) => {
  const { companyCode, hiddenModule } = props

  const [data, setdata] = useState([])

  const [total, setTotal] = useState(0)

  const columns: any[] = [
    {
      title: '序号',
      dataIndex: 'index',
      width: 80,
      render: (_: string, _record: any, index: number) => <>{index + 1 + (pagination.current - 1) * pagination.pageSize}</>
    },
    {
      title: '股东',
      dataIndex: 'sholderName',
      ellipsis: true
    },
    {
      title: '股东类型',
      dataIndex: 'sholderType'
    },
    {
      title: '持股比例',
      dataIndex: 'proportion',
      render: (row: any, _record: any) => <span>{row ? `${row}%` : '--'}</span>
    },
    {
      title: '认缴出资额',
      dataIndex: 'conAmt',
      render: (row: any, _record: any) => <span>{row ? `${row}万人民币` : '--'}</span>
    },
    {
      title: '认缴出资日期',
      dataIndex: 'conDate'
    }
  ]
  /**
   * @description 获取表格数据
   */
  const getList = async () => {
    const res = await postCompanyInfoDetailQueryShareholderInformation({
      current: pagination.current,
      pageSize: pagination.pageSize,
      companyCode: companyCode || '940bc2dc60b3adcddc804ca05ead707d'
    })
    setdata(res.data.list)

    setTotal(res.data.total)

    if (res.data.total) hiddenModule(res.data.total)

    return res.data
  }
  const { pagination } = useNewPage(getList)
  return (
    <div id="股东信息">
      {total ? (
        <div>
          <div className="second_title mb-21px">股东信息</div>
          <HsAdminTablePage
            scroll={{ x: 1000, y: 650 }}
            columns={columns}
            dataSource={data}
            id="intellectual-property-patent"
            pagination={pagination}
            rowKey={(record: any) => `${record.sholderName}${record.sholderType}`}
            size="small"
          />
        </div>
      ) : null}
    </div>
  )
}
export default memo(ShareholderInformation)
